- [Instructor] When you plot data in MATLAB,
your script displays data in the figure window.
In this movie,
I will show you how to save a plot to a file
and also print it if required.
I've just run MATLAB
and want to create a script,
so I will go over to the Home tab
and click the New Script button.
I could've also pressed Control + N.
Now I'm in the script editor,
so I can define the script for my chart.
The scenario I have in mind is for four stores
with sales data,
so I'll type storeid equal,
and the store IDs will be values in the range
from 147 to 150 incremented by one,
so that's 147 colon 150.
I don't want it to appear when the script is run,
so I will suppress output with a semicolon and Enter.
Now for the sales,
I'll just type sales variable equal,
and then in square brackets I'll have 150 comma 200
comma 125 comma 275.
And right square bracket
and a semicolon again to suppress and Enter.
I want to make sure there are no existing figures
that I'll be overwriting,
so I will use the clf command,
and that clears the figure area.
Press Enter.
Now I can create my bar chart.
So I'll just type bar, B-A-R,
left parentheses storeid,
which contains the column or x variables,
and then sales,
which contains the value or y variables.
And I won't worry about titles or labels.
And I'll press Control + S
and I will save this as saveplot.
And press Enter,
and there I have it.
Now I can close the editor window
by clicking the Close Editor button,
and run the plot to create it
by typing the name of the file,
which is saveplot,
and I can see that over on the left in my current folder.
So Enter,
and I get my plot
If I want to save this plot as a separate file,
I can go to the File menu
and then click Save As.
Doing to displays the Save As dialog box,
and I can save the image as a MATLAB figure,
or if I click the down arrow,
you see that I can also save it
in a variety of image file types.
I'll go ahead
and save it as a Portable Network Graphics file, or .png.
So I click that from save as type,
and for the file name,
I will just call it storedata.
And press Enter to save,
and my file has been saved.
And you'll notice that the storedata.png file
now appears in the current folder on the left.
If I want to print this figure,
I can just go to the File menu and click Print
or press Control + P,
and when I do,
the Print dialog box shows up,
and what you see will depend on your network,
but I have my printer displayed,
and if I want to print,
I can just click OK.
Or if I think better of it,
I can just click Cancel.
So as you can see,
you can save a figure for use in electronic documents
or print it for paper documents.